package com.qtyx.nms.util

import com.qtyx.nms.MyApp.Companion.getMyAppContext

/**
 * 单位转换工具
 */
object DisplayUtil {
    fun px2dp(pxValue: Float): Int {
        val scale =getMyAppContext().resources.displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }

    fun dp2px(dipValue: Float): Int {
        val scale =getMyAppContext().resources.displayMetrics.density
        return (dipValue * scale + 0.5f).toInt()
    }

    fun px2sp(pxValue: Float): Int {
        val fontScale =getMyAppContext().resources.displayMetrics.scaledDensity
        return (pxValue / fontScale + 0.5f).toInt()
    }

    fun sp2px(spValue: Float): Int {
        val fontScale =getMyAppContext().resources.displayMetrics.scaledDensity
        return (spValue * fontScale + 0.5f).toInt()
    }
}